package com.llc.mall.user.domain.user.service.impl;

import com.llc.mall.user.domain.user.entity.User;
import com.llc.mall.user.domain.user.factory.UserFactory;
import com.llc.mall.user.domain.user.objectvalue.UserProfile;
import com.llc.mall.user.domain.user.repository.UserRepository;
import com.llc.mall.user.domain.user.service.UserDomainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 *
 */
@Slf4j
@Service
public class UserDomainServiceImpl implements UserDomainService {

    private final UserRepository userRepository;

    public UserDomainServiceImpl(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    @Override
    public Long register(UserProfile userProfile) {
        //实体生产
        User user = UserFactory.factory(userProfile);
        user.register();
        return userRepository.save(user);
    }

    @Override
    public void modify(Long userId, UserProfile userProfile) {
        User user = userRepository.findById(userId);
        user.modify(userProfile);
        userRepository.save(user);
    }
}
